package main

import "fmt"

func main() {
	fmt.Println(getMaxLen([]int{0, 1, -2, -3, -4}))
}

func getMaxLen(nums []int) int {
	dpP, dpN := 0, 0
	if nums[0] > 0 {
		dpP = 1
	} else if nums[0] < 0 {
		dpN = 1
	}
	max := dpP
	for i := 1; i < len(nums); i++ {
		if nums[i] > 0 {
			dpP = dpP + 1
			if dpN != 0 {
				dpN = dpN + 1
			} else {
				dpN = 0
			}
		} else if nums[i] < 0 {
			if dpN == 0 {
				dpN, dpP = dpP+1, 0
			} else {
				dpN, dpP = dpP+1, dpN+1
			}
		} else {
			dpN, dpP = 0, 0
		}
		if dpP > max {
			max = dpP
		}
	}
	return max
}
